package cn.edu.buu.hospital.entity;

import java.io.Serializable;

/**
 * 用户实体类（包含患者和医生，通过type区分）
 */
public class User implements Serializable {
    // 用户ID（主键）
    private Long userid;
    // 登录用户名
    private String username;
    // 登录密码
    private String userpwd;
    // 用户类型：1-患者，2-医生，3-管理员
    private Integer type;
    // 性别：1-男，2-女
    private Integer sex;
    // 联系电话
    private String phone;
    // 身份证号
    private String idcard;
    // 头像URL
    private String headpic;
    // 状态：0-启用，1-禁用
    private Integer status;
    // 邮箱
    private String email;
    // 密码（兼容字段）
    private String password;
    // 创建时间
    private String createTime;
    // 真实姓名
    private String realName;
    // 出生日期
    private String birthday;


    // 无参构造函数
    public User() {
    }

    // getter和setter方法
    public Long getUserid() {
        return userid;
    }

    public void setUserid(Long userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getIdcard() {
        return idcard;
    }

    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }

    public String getHeadpic() {
        return headpic;
    }

    public void setHeadpic(String headpic) {
        this.headpic = headpic;
    }
    
    public Integer getStatus() {
        return status;
    }
    
    public void setStatus(Integer status) {
        this.status = status;
    }
    
    public String getEmail() {
        return email;
    }
    
    public void setEmail(String email) {
        this.email = email;
    }
    
    public String getPassword() {
        return password != null ? password : userpwd;
    }
    
    public void setPassword(String password) {
        this.password = password;
        this.userpwd = password; // 同时设置userpwd字段
    }
    
    public String getCreateTime() {
        return createTime;
    }
    
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
    
    // getter和setter方法 - realName
    public String getRealName() {
        return realName;
    }
    
    public void setRealName(String realName) {
        this.realName = realName;
    }
    
    // getter和setter方法 - birthday
    public String getBirthday() {
        return birthday;
    }
    
    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }
    
    // 性别字段getter（用于兼容profile.jsp中的gender字段）
    public String getGender() {
        if (sex == null) {
            return null;
        }
        switch (sex) {
            case 1:
                return "male";
            case 2:
                return "female";
            default:
                return "other";
        }
    }
    
    // 性别字段setter（用于兼容profile.jsp中的gender字段）
    public void setGender(String gender) {
        if (gender == null) {
            this.sex = null;
            return;
        }
        switch (gender) {
            case "male":
                this.sex = 1;
                break;
            case "female":
                this.sex = 2;
                break;
            default:
                this.sex = null;
                break;
        }
    }

    // 兼容AdminController中使用的headPic属性名
    public void setHeadPic(String headpic) {
        this.headpic = headpic;
    }

    public String getHeadPic() {
        return this.headpic;
    }

    // 兼容AdminController中使用的userPassword属性名
    public void setUserPassword(String userpwd) {
        this.userpwd = userpwd;
    }

    // 兼容AdminController中使用的userType属性名
    public void setUserType(Integer type) {
        this.type = type;
    }

    public Integer getUserType() {
        return this.type;
    }
    
    // idCard属性getter（兼容profile.jsp中的idCard字段）
    public String getIdCard() {
        return this.idcard;
    }
    
    // idCard属性setter（兼容profile.jsp中的idCard字段）
    public void setIdCard(String idcard) {
        this.idcard = idcard;
    }

    // toString方法，用于调试
    @Override
    public String toString() {
        return "User{" +
                "userid=" + userid +
                ", username='" + username + '\'' +
                ", userpwd='" + userpwd + '\'' +
                ", type=" + type +
                ", sex=" + sex +
                ", phone='" + phone + '\'' +
                ", idcard='" + idcard + '\'' +
                ", headpic='" + headpic + '\'' +
                ", status=" + status +
                ", email='" + email + '\'' +
                ", password='" + password + '\'' +
                ", createTime='" + createTime + '\'' +
                ", realName='" + realName + '\'' +
                ", birthday='" + birthday + '\'' +
                '}';
    }

}